﻿using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sasa.QualityTools.CodeAnalysis.Core.Models;
using Sasa.QualityTools.CodeAnalysis.Core.Tests.Unit.Instruments;

namespace Sasa.QualityTools.CodeAnalysis.Core.Tests.Unit.Models
{
    [TestFixture]
    public class CodeAnalysisResultValueFileNameFilterTest
    {
        private CodeAnalysisResultValueFileNameFilter testee;


        [SetUp]
        public void SetUp()
        {
            testee = new CodeAnalysisResultValueFileNameFilter();
        }

        [Test]
        public void IsAvailableShouldReturnFalseWhenArgumentIsNull()
        {
            Assert.IsFalse(testee.IsAvailable(null));
        }

        [Test]
        public void IsAvailableShouldReturnTrueWhenAssemblyPathIsNull()
        {
            var value = new DummyCodeAnalysisResultValue { Path = "!@#$<>#$^*$%^'&\"" };
            Assert.IsTrue(testee.IsAvailable(value));
        }

        [Test]
        public void IsAvailableShouldReturnFalseWhenPatternMatchesFileName()
        {
            var value = new DummyCodeAnalysisResultValue { Path = "C:\\Dummy.Designer.cs" };
            testee.Patterns.Add("^.+\\.Designer\\.cs$");
            Assert.IsFalse(testee.IsAvailable(value));
        }

        [Test]
        public void IsAvailableShouldReturnTrueWhenPatternDoesNotMatchFileName()
        {
            var value = new DummyCodeAnalysisResultValue { Path = "C:\\Dummy.Designer.cs" };
            testee.Patterns.Add("^.+\\.Generated\\.cs$");
            Assert.IsTrue(testee.IsAvailable(value));
        }

        [TestCase("C:\\Dummy.Designer.cs", Result = false)]
        [TestCase("C:\\Dummy.Generated.cs", Result = false)]
        [TestCase("C:\\Dummy.g.cs", Result = true)]
        public bool IsAvailableShouldReturnFalseWhenAnyPatternMatchesFileName(string path)
        {
            var value = new DummyCodeAnalysisResultValue { Path = path };
            testee.Patterns.Add("^.+\\.Designer\\.cs$");
            testee.Patterns.Add("^.+\\.Generated\\.cs$");
            return testee.IsAvailable(value);
        }

        [TestCase("C:\\Dummy.Designer.cs", Result = false)]
        [TestCase("C:\\Dummy.Generated.cs", Result = false)]
        [TestCase("C:\\Dummy.g.cs", Result = true)]
        public bool IsAvailableShouldIgnoreInvalidPattern(string path)
        {
            var value = new DummyCodeAnalysisResultValue { Path = path };
            testee.Patterns.Add("^.+\\.Designer\\.cs$");
            testee.Patterns.Add(null);
            testee.Patterns.Add("^.+\\.Generated\\.cs$");
            return testee.IsAvailable(value);
        }
    }
}
